package logic

import (
	"context"
	"fmt"
	"medi-doc/model"

	"medi-doc/doctorrpc/doctorrpc"
	"medi-doc/doctorrpc/internal/svc"

	"github.com/zeromicro/go-zero/core/logx"
)

type DoctorUpdateLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewDoctorUpdateLogic(ctx context.Context, svcCtx *svc.ServiceContext) *DoctorUpdateLogic {
	return &DoctorUpdateLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *DoctorUpdateLogic) DoctorUpdate(in *doctorrpc.DoctorUpdateRequest) (*doctorrpc.DoctorUpdateResponse, error) {
	// todo: add your logic here and delete this line

	var doctor model.Doctor
	model.DB.Debug().Where("id=?", in.Id).Find(&doctor)
	if in.Id == 0 {
		return nil, fmt.Errorf("无数据")
	}
	doctor = model.Doctor{

		Name:    in.Name,
		Img:     in.Img,
		Address: in.Address,
		Zw:      in.Zw,
		Class:   in.Class,
		Bq:      in.Bq,
	}
	model.DB.Debug().Updates(&doctor)
	return &doctorrpc.DoctorUpdateResponse{
		Id: int64(doctor.ID),
	}, nil
}
